package edu.nf.exam.dao.impl;

import edu.nf.exam.dao.TaskInfoDao;
import edu.nf.exam.entity.TaskInfo;
import edu.nf.exam.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Author : QYM
 * @create 2021/6/17
 * 任务信息表--接口实现类
 */
public class TaskInfoDaoImpl implements TaskInfoDao {
    /**
     * 添加
     * @param taskInfo
     * @return
     */
    @Override
    public int add(TaskInfo taskInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        int r = sqlSession.getMapper(TaskInfoDao.class).add(taskInfo);
        sqlSession.close();
        return r;
    }

    /**
     * 分页查询
     * @param title
     * @param levelName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<TaskInfo> listTask(String title, String levelName, Integer pageNum, Integer pageSize) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<TaskInfo> list = sqlSession.getMapper(TaskInfoDao.class).listTask(title, levelName, pageNum, pageSize);
        sqlSession.close();
        return list;
    }

    /**
     * 根据年级查询
     * @param levelName
     * @return
     */
    @Override
    public List<TaskInfo> selectByLevel(String levelName) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<TaskInfo> list = sqlSession.getMapper(TaskInfoDao.class).selectByLevel(levelName);
        sqlSession.close();
        return list;
    }

    /**
     * 多条件查询
     * @param taskInfo
     * @return
     */
    @Override
    public List<TaskInfo> select(TaskInfo taskInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<TaskInfo> list = sqlSession.getMapper(TaskInfoDao.class).select(taskInfo);
        sqlSession.close();
        return list;
    }
}
